package com.asdf.db.operations.airport;

import java.util.List;

import com.asdf.db.results.ResultStatus;
import com.asdf.db.results.airport.AirportResult;
import com.asdf.entities.Airport;

/**
 * @author Artem Barger
 * 
 * Operation which is iterates over airport dataset and 
 * look ups for specified airport.
 *
 */
public class LocateAirport extends AirportOperation
{

	private String ID;
	
	/**
	 * @param dataSource the airports dataset.
	 */
	public LocateAirport( List< Airport> dataSource)
	{
		this.dataSource = dataSource;
	}
	
	/**
	 * Set the id of airport for look up.
	 * 
	 * @param id the id of airport for look up.
	 */
	public void setAirportID( String id)
	{
		this.ID = id;
	}
	
	@Override
	public AirportResult perform( )
	{
		AirportResult result = new AirportResult( );
		
		for ( Airport airport:dataSource)
		{
			if ( airport.getId( ).equalsIgnoreCase(  ID))
			{
				result.setStatus( ResultStatus.OK);
				result.addToResultSet( airport);
				return result;
			}
		}
		
		result.setStatus( ResultStatus.NotFound);
		return result;
	}

}
